/*
 * @Author: your name
 * @Date: 2021-04-25 19:19:29
 * @LastEditTime: 2021-09-06 16:26:27
 * @LastEditors: your name
 * @Description: In User Settings Edit
 * @FilePath: /ant-design-pro-5/src/pages/dashboard/amap/model.ts
 */
import type { Effect, Reducer } from "umi";

export interface ModalState {
  currentItem?: string;
  modalVisible?: boolean;
  modalType?: string;
  cardVisible?: boolean;
  intersection?: any;
  equipment?: [];
  intersections?: [];
  imageList?: [];
}

export interface ModelType {
  namespace: string;
  state: ModalState;
  reducers: {
    showRoadModal: Reducer<ModalState>;
    hideRoadModal: Reducer<ModalState>;
    hideCard: Reducer<ModalState>;
    queryDateilData: Reducer<ModalState>;
    queryIntersectionData: Reducer<ModalState>;
  };
  effects: {
    fetch: Effect;
    showDetail: Effect;
  };
}

const initState: any = {
  currentItem: "",
  modalVisible: false,
  modalType: "create",
  cardVisible: false,
  intersection: {},
  equipment: [],
  intersections: [
    {
      title: "T1",
      lnglat: [113.03868882358074, 28.573423076220266],
      controlPlan: false,
    },
  ],
  imageList: [],
};

const Model: ModelType = {
  namespace: "amap",
  state: initState,
  effects: {
    *fetch({ payload }, { call, put }) {},
    *showDetail({ payload }, { call, put }) {
      yield put({
        type: "queryDateilData",
      });
    },
  },
  reducers: {
    queryDateilData(state, { payload }) {
      return { ...state, ...payload, cardVisible: true };
    },
    queryIntersectionData(state, { payload }) {
      return { ...state };
    },
    showRoadModal(state, { payload }) {
      return { ...state, ...payload, modalVisible: true };
    },
    hideRoadModal(state, { payload }) {
      return { ...state, ...payload, modalVisible: false };
    },
    hideCard(state, { payload }) {
      return { ...state, ...payload, cardVisible: false };
    },
  },
};

export default Model;
